package com.ligang.flowable.mulitiInstance;

import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.delegate.DelegateExecution;
import org.springframework.stereotype.Component;

import java.io.Serializable;

/**
 * ClassName:用户多实例监听器
 * Package:org.flowable.listener
 * Description:
 *
 * @Date:2022/4/30 13:50
 * @Author:gang.li
 **/
@Slf4j
@Component("mulitiInstanceCompleteTask")
public class MulitiInstanceCompleteTask implements Serializable {

    /**
     * 完成实例需要触发的方法
     * @param execution
     * @return
     * 返回值为True，表示会签任务可以结束了
     * 返回值为False，表示会签任务还未结束
     */
    public boolean isCompleteTask(DelegateExecution execution){
        log.info("======================================");
        log.info("总的会签任务数量为：{}",execution.getVariable("nrOfInstances"));
        log.info("当前剩余的会签任务数量为：{}",execution.getVariable("nrOfActiveInstances"));
        log.info("已经完成的会签任务数量为：{}",execution.getVariable("nrOfCompletedInstances"));

        //有一个人同意就通过
        Boolean flag = (Boolean)execution.getVariable("flag");
        log.info("当前的意见是：{}",flag);
        log.info("======================================");
        return flag;

    }

}
